import { Vec3, math } from "cc";

// 网络上用于传递球信息
export class NetBall {
  public name: string = '';
  public pos: Vec3 = Vec3.ZERO;
  public vel: Vec3 = Vec3.ZERO;
  public ang: Vec3 = Vec3.ZERO;
  public active: number = 0;
  constructor(name: string, pos: Vec3, v: Vec3, isActive: boolean) {
    this.name = name;
    this.pos = pos.clone();
    this.vel = v.clone();
    this.active = isActive ? 1 : 0;
  }
  public setAngVel(v: Vec3) {
    this.ang = v.clone();
  }
}

// 网络上传递当前 帧 的信息
export class NetKeyFrame {
  step: number;
  seq: number;
  timestamp: number;
  flag: number; // 0 默认正常的一帧数据，1 结束帧
  balls: Array<NetBall> = [];
  constructor(step: number, seq: number, timestamp: number, flag: number, balls: Array<NetBall>) {
    this.step = step;
    this.seq = seq;
    this.timestamp = timestamp;
    this.flag = flag;
    this.balls = balls
  }
}

// 击打白球传递的信息
export class NetHitMainBall {
  pos: Vec3; // 白球的位置
  vel: Vec3; // 速度
  sop: Vec3; // spin的偏移位置
  constructor(pos: Vec3, vel: Vec3, sop: Vec3) {
    this.pos = pos.clone();
    this.vel = vel.clone();
    this.sop = sop.clone();
  }
}

// 击打白球传递信息
export class NetHitMainBallFrame {
  step: number;
  hitMainBall: NetHitMainBall;
  initFrame: NetKeyFrame;
  constructor() {
    this.step = 0;
  }
  public setMainBall(pos: Vec3, vel: Vec3, sop: Vec3) {
    this.hitMainBall = new NetHitMainBall(pos, vel, sop);
  }
  public setKeyFrame(step: number, seq: number, timestamp: number, flag: number, balls: Array<NetBall>) {
    this.step = step;
    this.initFrame = new NetKeyFrame(step, seq, timestamp, flag, balls);
  }
}

export class EndStepSyncFrame {
  step: number;
  firstHitBallName: string;
  endFrame: NetKeyFrame;
  hitBallListName: string[]; // 进球的球名称
  constructor(step: number, fhbn: string, ef: NetKeyFrame, balls: string[]) {
    this.step = step;
    this.firstHitBallName = fhbn;
    this.endFrame = ef;
    this.hitBallListName = balls;
  }
}